home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / mouse.exe / MOUSEISR.PAS < prev    next >
Pascal/Delphi Source File  |  1989-06-01  |  4KB  |  88 lines

  1.  
  2. { This is the MOUSEISR.PAS include file for the MOUSE.PAS unit }
  3. { This include file contains the mouse ISR routines and Exit handlers }
  4.  
  5. {***************************************************************************}
  6. {  ****   These are special procedures -- Caution: handle with care   ****  }
  7.  
  8. { special global variables localized to this area}
  9. const ClkVect = $1C;                     {55ms system clock interrupt number}
  10. var ExitSave:Pointer;                        {saved previous ExitPoc pointer}
  11.     Old1Cvect:Pointer;                            {old 55ms interrupt vector}
  12.     Int1Cvect:Pointer absolute $00:$70;    {address of 55ms interrupt vector}
  13.  
  14. {---------------------------------------------------------------------------}
  15. {Exit procedure}
  16. { restores stuff on exit from main program }
  17.  
  18. {$F+} procedure MouseExit;                                  {<-- must be far}
  19. begin
  20.    ExitProc := ExitSave;                   {restore next exit procedure call}
  21.    if MouseVisible then           {make sure the mouse is off before exiting}
  22.      HideMouse;
  23.    if HercGraphMouse then               {turn off the Herc mouse if it is on}
  24.      SetHercMouse(-1);
  25.    if MouseHooked then                             {if mouse hooked to clock}
  26.      SetIntVec(ClkVect,Old1Cvect);            {then restore old clock vector}
  27. end;
  28.  
  29. {---------------------------------------------------------------------------}
  30. { mouse clock ISR routine }
  31. { hooks the ReadMouse routine to the system clock }
  32. { Use the MouseClock procedure to attach or detach this ISR }
  33.  
  34. {$F+} procedure ClockMouseRead; interrupt;    {<-- must be far and interrupt}
  35. begin
  36.   inline($FB);                                         {re-enable interrupts}
  37.   if not(MouseBusy) then          {if mouse is still busy, we wrapped around}
  38.   begin
  39.     ReadMouse;                                               {read the mouse}
  40.     { Additional or alternate ISR code can go here - See warning note below }
  41.   end;
  42.  
  43.   {Finally, we end the ISR with a link to the existing clock routines}
  44.   inline($9C/$FF/$1E/Old1Cvect);   {pushf;  call far old1cvect  ;link to old}
  45. end;
  46.  
  47. { Warning: If you add code to this routine, or change it, use extreme care }
  48. { in what you do. Poorly created ISR routines can create major problems }
  49. { that cannot be readily detected. Remember that most debugger's }
  50. { (including Borland's) are not able to trace into an ISR. You will need a }
  51. { low-level debugger like Periscope to do that sort of thing. }
  52. { Caution: Since the ClockMouseRead interrupt procedure is hooked to the }
  53. { system clock, it is repeated at 55ms intervals. Do not allow the code }
  54. { in the routine to exceed that time frame or it will cause the stack to }
  55. { overflow. You can add code after the ReadMouse procedure call, or replace }
  56. { the ReadMouse procedure call with your own, but use extreme care in doing }
  57. { so, since it is easy to break this code, and you can't easily debug it if }
  58. { something is wrong. }
  59.  
  60. {---------------------------------------------------------------------------}
  61. {Hooks the Mouse function to the system clock}
  62. {State = true hooks the mouse up, State = false disconnects the mouse}
  63. {This function calls the ReadMouse function once every 55ms. This can}
  64. {help speed up the mouse control and make it more consistant, especially}
  65. {when using simulated BGI mouse cursor. When the mouse is hooked to the}
  66. {system clock you do not need to continuously poll the ReadMouse procedure}
  67.  
  68. procedure MouseClock(State:Boolean);
  69. begin
  70.   if State then
  71.   begin
  72.     if MouseHooked then Exit;      {the mouse is already hooked to the clock}
  73.     MouseHooked := true;                   {if the mouse is not hooked, then}
  74.     Old1Cvect := Int1Cvect;                       {save old clock vector and}
  75.     SetIntVec(ClkVect,@ClockMouseRead);                      {attach our own}
  76.   end
  77.   else
  78.   begin
  79.     if not(MouseHooked) then Exit;       {if mouse currently hooked to clock}
  80.     SetIntVec(ClkVect,Old1Cvect);             {then restore old clock vector}
  81.     MouseHooked := false;                                     {and unhook it}
  82.   end;
  83. end;
  84.  
  85. {---------------------------------------------------------------------------}
  86. { End Of MOUSEISR.PAS include file }
  87.  
  88.